import type { Base, Page } from "@/api/types";
import { http } from "@/utils/http";
import { createFormData } from "@pureadmin/utils";

export type Employee = Base & {
  userId?: string;
  workId?: string;
  jobId?: string;
  job?: string;
  deptId?: string;
  dept?: string;
  name?: string;
  idCard?: string;
  phone?: string;
  gender?: string;
  married?: string;
  education?: string;
  salary?: number;
  hiredate?: string;
  termdate?: string;
  status?: string;
};

export const getEmployeeList = (params?: object) => {
  return http.request<Page<Employee>>("get", "/employee", params);
};
export const addEmployee = (params?: Employee) => {
  return http.request<boolean>("post", "/employee", params);
};
export const updateEmployee = (params?: Employee) => {
  return http.request<boolean>("put", "/employee", params);
};
export const deleteEmployee = (id: string) => {
  return http.request<boolean>("delete", "/employee", { id: id });
};
export const leaveEmployee = (id: string) => {
  return http.request<boolean>("put", "/employee/leave", { id: id });
};
export const getSimpleEmployeeList = () => {
  return http.request<Array<Employee>>("get", "/employee/simple");
};

export const upload = (file: File) => {
  const formData = createFormData({ file: file });
  return http.upload<string>("/employee/upload", {}, formData);
};
